using Tycho.Parser.Tokens;

namespace Tycho.Parser.Peg {
    public class ChoiceProduction<Context> : Production<Context> {
        public readonly Production<Context>[] Productions;

        public ChoiceProduction (params Production<Context>[] productions) {
            Productions = productions;
        }

        protected override ParseResult<Context> ReallyParse (Token[] tokens, int index, Context context) {
            foreach (var p in Productions) {
                ParseResult<Context> result = p.Parse (tokens, index, context);

                if (result != null) {
                    return result;
                }
            }

            return null;
        }
    }
}